package edu.cicese.alz.reports;

import edu.cicese.alz.FrameReport;
import edu.cicese.alz.TimeUtil;
import edu.cicese.alz.swing.CustomButton;
import edu.cicese.alz.swing.DynamicCardLayout;
import edu.cicese.alz.swing.SwingUtil;
import edu.cicese.alz.swing.calendar.DateChooser;
import edu.cicese.alz.swing.calendar.TextFieldDateEditor;
import edu.cicese.alz.util.PropertyUtil;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.TreeSet;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 2/08/12
 * Time: 11:33 AM
 */
public class CombinedPane extends ReportPane {

	private Box boxCombined;

	// Types
	private JCheckBox chbAccelerometer, chbGPS, chbNFC;
	private AccelerometerPane accPane;
	private GPSPane gpsPane;
	private NFCPane nfcPane;

	// Period
	private TextFieldDateEditor txtPeriodFrom, txtPeriodTo;
	private DateChooser dChooserFrom, dChooserTo;
	private JRadioButton rbtPeriodAll, rbtPeriodFrom;
	private JSpinner sIntervalFrom, sIntervalTo;

	// Advanced
	private JPanel pAdvancedAccelerometer, pAdvancedGPS, pAdvancedNFC;
	private JSlider jsAccelerometerNoData, jsAccelerometerGeneral;
	private JSlider jsGPSNoData, jsGPSHome, jsGPSOut;
	private JSlider jsNFCNoData, jsNFCGeneral;

	private JList<String> listLayers;
	private DefaultListModel listLayersModel = new DefaultListModel();
	private CustomButton btnUp, btnDown;

	public CombinedPane(AccelerometerPane accPane, GPSPane gpsPane, NFCPane nfcPane) {
		initComponents();
		initOptionScrollPane(boxCombined);
		loadOptions();

		this.accPane = accPane;
		this.gpsPane = gpsPane;
		this.nfcPane = nfcPane;
	}

	private void initComponents() {
		// Type
		chbAccelerometer = SwingUtil.createCheckBox("Accelerometer");
		chbAccelerometer.addActionListener(new TypeActionListener());
		chbGPS = SwingUtil.createCheckBox("GPS");
		chbGPS.addActionListener(new TypeActionListener());
		chbNFC = SwingUtil.createCheckBox("NFC");
		chbNFC.addActionListener(new TypeActionListener());

		Box boxTypes = createVerticalBox(new Component[]{
				chbAccelerometer,
				chbGPS,
				chbNFC
		}, 0);

		Box boxTypeContent = createVerticalBox(new Component[]{
				boxTypes
		});


		// Users
		Box boxUsersContent = createUsersBox();


		// Period
		rbtPeriodAll = SwingUtil.createRadioButton("All");
		rbtPeriodAll.setModel(FrameReport.rbtPeriodAllModel);
		rbtPeriodFrom = SwingUtil.createRadioButton("From:");
		rbtPeriodFrom.setModel(FrameReport.rbtPeriodFromModel);
		ButtonGroup rgPeriod = new ButtonGroup();
		rgPeriod.add(rbtPeriodAll);
		rgPeriod.add(rbtPeriodFrom);


		txtPeriodFrom = new TextFieldDateEditor();
		txtPeriodFrom.setDocument(FrameReport.txtDayFromModel);

		txtPeriodTo = new TextFieldDateEditor();
		txtPeriodTo.setDocument(FrameReport.txtDayToModel);

		txtPeriodFrom.getDocument().addDocumentListener(new DateDocumentListener(txtPeriodFrom, txtPeriodTo));
		dChooserFrom = new DateChooser(new Date(), "dd-MM-yyyy", txtPeriodFrom);

		txtPeriodTo.getDocument().addDocumentListener(new DateDocumentListener(txtPeriodFrom, txtPeriodTo));
		dChooserTo = new DateChooser(new Date(), "dd-MM-yyyy", txtPeriodTo);

		Box boxDays = createHorizontalBox(new Component[]{
				rbtPeriodFrom,
				Box.createHorizontalStrut(5),
				dChooserFrom,
				Box.createHorizontalStrut(3),
				new JLabel("to:"),
				Box.createHorizontalStrut(5),
				dChooserTo,
		});

		sIntervalFrom = SwingUtil.createSpinner(new Date(), FrameReport.sHourFromModel);
		sIntervalTo = SwingUtil.createSpinner(new Date(), FrameReport.sHourToModel);

		Box boxInterval = createHorizontalBox(new Component[]{
				new JLabel("From:"),
				Box.createHorizontalStrut(5),
				sIntervalFrom,
				Box.createHorizontalStrut(5),
				new JLabel("to:"),
				Box.createHorizontalStrut(5),
				sIntervalTo
		});

		Box boxPeriod1 = createVerticalBox(new Component[]{
				rbtPeriodAll,
				boxDays
		});

		Box boxPeriod2 = createVerticalBox(new Component[]{
				boxInterval
		});

		JPanel pPeriod = createContentPane(new Box[]{
				boxPeriod1,
				boxPeriod2
		});


		// Advanced
		listLayers = new JList(listLayersModel);
//		listLayers.setPreferredSize(new Dimension(100, listLayers.getPreferredSize().height));
		listLayers.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		listLayers.setAlignmentX(Component.LEFT_ALIGNMENT);
		listLayers.setBorder(BorderFactory.createCompoundBorder(
				BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1),
				BorderFactory.createLineBorder(Color.WHITE, 4)));

		Box boxLayersList = createVerticalBox(new Component[]{
				listLayers,
				Box.createVerticalStrut(3)
		});

		btnUp = SwingUtil.createCustomButton("", "Move up", getIcon("b_up"), Color.WHITE);
		btnUp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				actionMoveUp();
			}
		});
		btnDown = SwingUtil.createCustomButton("", "Move down", getIcon("b_down"), Color.WHITE);
		btnDown.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				actionMoveDown();
			}
		});

		Box boxUpDown = createHorizontalBox(new Component[]{
				Box.createHorizontalStrut(3), btnDown, btnUp
		});

		JPanel pLayers = createContentPane(new Box[]{
				boxLayersList, boxUpDown
		});

		Box boxLayers = createVerticalBox(new Component[]{
				createTitlePane("Layer's order", SwingUtil.cBackground),
				Box.createVerticalStrut(4),
				pLayers
		}, 0);


		int sliderWidth = 100;

		jsAccelerometerNoData = SwingUtil.createSlider(SwingConstants.HORIZONTAL, 0, 255, 0, 120, 20);
		jsAccelerometerNoData.addChangeListener(new OpacityChangeListener());
		jsAccelerometerGeneral = SwingUtil.createSlider(SwingConstants.HORIZONTAL, 0, 255, 0, 120, 20);
		jsAccelerometerGeneral.addChangeListener(new OpacityChangeListener());


		Box boxAccelerometer1 = createHorizontalBox(new Component[]{
				SwingUtil.createLabel("No-data opacity", sliderWidth, 20),
				jsAccelerometerNoData
		});
		Box boxAccelerometer2 = createHorizontalBox(new Component[]{
				SwingUtil.createLabel("General opacity", sliderWidth, 20),
				jsAccelerometerGeneral
		});

		Box boxAccelerometerContent = createVerticalBox(new Component[]{
				boxAccelerometer1,
				Box.createVerticalStrut(3),
				boxAccelerometer2
		});

		Box boxAccelerometer = createVerticalBox(new Component[]{
				createTitlePane("Accelerometer", SwingUtil.cBackground),
				Box.createVerticalStrut(4),
				boxAccelerometerContent,
				Box.createVerticalStrut(4)
		}, 0);


		jsGPSNoData = SwingUtil.createSlider(SwingConstants.HORIZONTAL, 0, 255, 0, 120, 20);
		jsGPSNoData.addChangeListener(new OpacityChangeListener());
		jsGPSHome = SwingUtil.createSlider(SwingConstants.HORIZONTAL, 0, 255, 0, 120, 20);
		jsGPSHome.addChangeListener(new OpacityChangeListener());
		jsGPSOut = SwingUtil.createSlider(SwingConstants.HORIZONTAL, 0, 255, 0, 120, 20);
		jsGPSOut.addChangeListener(new OpacityChangeListener());

		Box boxGPS1 = createHorizontalBox(new Component[]{
				SwingUtil.createLabel("No-data opacity", sliderWidth, 20),
				jsGPSNoData
		});
		Box boxGPS2 = createHorizontalBox(new Component[]{
				SwingUtil.createLabel("Home opacity", sliderWidth, 20),
				jsGPSHome
		});
		Box boxGPS3 = createHorizontalBox(new Component[]{
				SwingUtil.createLabel("Out opacity", sliderWidth, 20),
				jsGPSOut
		});

		Box boxGPSContent = createVerticalBox(new Component[]{
				boxGPS1,
				Box.createVerticalStrut(3),
				boxGPS2,
				Box.createVerticalStrut(3),
				boxGPS3
		});

		Box boxGPS = createVerticalBox(new Component[]{
				createTitlePane("GPS", SwingUtil.cBackground),
				Box.createVerticalStrut(4),
				boxGPSContent,
				Box.createVerticalStrut(4)
		}, 0);


		jsNFCNoData = SwingUtil.createSlider(SwingConstants.HORIZONTAL, 0, 255, 0, 120, 20);
		jsNFCNoData.addChangeListener(new OpacityChangeListener());
		jsNFCGeneral = SwingUtil.createSlider(SwingConstants.HORIZONTAL, 0, 255, 0, 120, 20);
		jsNFCGeneral.addChangeListener(new OpacityChangeListener());

		Box boxNFC1 = createHorizontalBox(new Component[]{
				SwingUtil.createLabel("No-data opacity", sliderWidth, 20),
				jsNFCNoData
		});
		Box boxNFC2 = createHorizontalBox(new Component[]{
				SwingUtil.createLabel("General opacity", sliderWidth, 20),
				jsNFCGeneral
		});

		Box boxNFCContent = createVerticalBox(new Component[]{
				boxNFC1,
				Box.createVerticalStrut(3),
				boxNFC2
		});

		Box boxNFC = createVerticalBox(new Component[]{
				createTitlePane("NFC", SwingUtil.cBackground),
				Box.createVerticalStrut(4),
				boxNFCContent,
				Box.createVerticalStrut(4)
		}, 0);


		pAdvancedAccelerometer = createCardPane(new DynamicCardLayout());
		pAdvancedAccelerometer.add("content", boxAccelerometer);
		pAdvancedAccelerometer.add("empty", createEmptyPane());

		pAdvancedGPS = createCardPane(new DynamicCardLayout());
		pAdvancedGPS.add("content", boxGPS);
		pAdvancedGPS.add("empty", createEmptyPane());

		pAdvancedNFC = createCardPane(new DynamicCardLayout());
		pAdvancedNFC.add("content", boxNFC);
		pAdvancedNFC.add("empty", createEmptyPane());

		CustomButton btnReloadPreview = SwingUtil.createCustomButton("", "Reload preview", getIcon("b_refresh"), Color.WHITE);
		btnReloadPreview.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				actionReloadPreview();
			}
		});

		Box boxPreview1 = createVerticalBox(new Component[]{
				boxLayers, pAdvancedAccelerometer, pAdvancedGPS, pAdvancedNFC
		}, 0);

		Box boxPreview2a = createVerticalBox(new Component[]{
				pCombinedPreview
		}, 0);

		Box boxPreview2b = createVerticalBox(new Component[]{
				btnReloadPreview
		}, 3);

		JPanel pPreview2 = createContentPane(new Box[]{
				boxPreview2a, boxPreview2b
		});

		Box boxPreview2 = createVerticalBox(new Component[]{
				createTitlePane("Preview", SwingUtil.cBackground),
				Box.createVerticalStrut(4),
				pPreview2
		}, 10);

		JPanel pPreview = createContentPane(new Box[]{
				boxPreview1, boxPreview2
		});


		// Saving options
		Box boxSavingContent = createSavingBox();

		boxCombined = Box.createVerticalBox();

		boxCombined.add(createTitlePane("Chart types"));
		boxCombined.add(Box.createVerticalStrut(7));
		boxCombined.add(boxTypeContent);
		boxCombined.add(Box.createVerticalStrut(7));

		boxCombined.add(createTitlePane("User(s)"));
		boxCombined.add(Box.createVerticalStrut(4));
		boxCombined.add(boxUsersContent);
		boxCombined.add(Box.createVerticalStrut(4));

		boxCombined.add(createTitlePane("Period"));
		boxCombined.add(Box.createVerticalStrut(4));
		boxCombined.add(pPeriod);
		boxCombined.add(Box.createVerticalStrut(4));

		boxCombined.add(createTitlePane("Saving options"));
		boxCombined.add(Box.createVerticalStrut(4));
		boxCombined.add(boxSavingContent);
		boxCombined.add(Box.createVerticalStrut(4));

		boxCombined.add(createTitlePane("Advanced options"));
		boxCombined.add(Box.createVerticalStrut(4));
		boxCombined.add(pPreview);
		boxCombined.add(Box.createVerticalStrut(6));
	}


	public void loadOptions() {
		boolean error = false;

		// Type
		try {
			chbAccelerometer.setSelected(PropertyUtil.getBoolean(PropertyUtil.REP_CMB_HAS_ACC));
			chbGPS.setSelected(PropertyUtil.getBoolean(PropertyUtil.REP_CMB_HAS_GPS));
			chbNFC.setSelected(PropertyUtil.getBoolean(PropertyUtil.REP_CMB_HAS_NFC));
		} catch (Exception e) {
			error = true;
		}
		checkTypeSelection();
		setLayers();
		setLayerList();

		// Users
		try {
			rbtUsersAll.setSelected(PropertyUtil.getBoolean(PropertyUtil.REP_USERS_ALL));
			txtUsers.setText(PropertyUtil.getProperty(PropertyUtil.REP_USERS));
		} catch (Exception e) {
			error = true;
		}
		rbtUsers.setSelected(!rbtUsersAll.isSelected());

		// Period
		try {
			rbtPeriodAll.setSelected(PropertyUtil.getBoolean(PropertyUtil.REP_PERIOD_ALL));
		} catch (Exception e) {
			error = true;
		}
		rbtPeriodFrom.setSelected(!rbtPeriodAll.isSelected());

		try {
			dChooserFrom.setDate(PropertyUtil.getDate(PropertyUtil.REP_PERIOD_FROM));
			dChooserTo.setDate(PropertyUtil.getDate(PropertyUtil.REP_PERIOD_TO));
		} catch (Exception e) {
			error = true;
		}

		try {
			sIntervalFrom.setValue(TimeUtil.getDate(PropertyUtil.getProperty(PropertyUtil.REP_INTERVAL_FROM)));
			sIntervalTo.setValue(TimeUtil.getDate(PropertyUtil.getProperty(PropertyUtil.REP_INTERVAL_TO)));
		} catch (Exception e) {
			error = true;
		}

		// Saving options
		try {
			chbSaveCharts.setSelected(PropertyUtil.getBoolean(PropertyUtil.REP_SAVE_CHARTS));
			chbShowCharts.setSelected(PropertyUtil.getBoolean(PropertyUtil.REP_SHOW_CHARTS));
		} catch (Exception e) {
			error = true;
		}

		// Advanced options
		jsAccelerometerNoData.setValue(PropertyUtil.getInt(PropertyUtil.REP_CMB_OPACITY_ACC_NO_DATA));
		jsAccelerometerGeneral.setValue(PropertyUtil.getInt(PropertyUtil.REP_CMB_OPACITY_ACC_GENERAL_OPACITY));
		jsGPSNoData.setValue(PropertyUtil.getInt(PropertyUtil.REP_CMB_OPACITY_GPS_NO_DATA));
		jsGPSHome.setValue(PropertyUtil.getInt(PropertyUtil.REP_CMB_OPACITY_GPS_HOME_OPACITY));
		jsGPSOut.setValue(PropertyUtil.getInt(PropertyUtil.REP_CMB_OPACITY_GPS_OUT_OPACITY));
		jsNFCNoData.setValue(PropertyUtil.getInt(PropertyUtil.REP_CMB_OPACITY_NFC_NO_DATA));
		jsNFCGeneral.setValue(PropertyUtil.getInt(PropertyUtil.REP_CMB_OPACITY_NFC_GENERAL_OPACITY));


		if (error) {
			showLoadError();
			loadDefaultOptions();
		}
	}

	public void saveOptions() {
		// Type
		//TODO

		// Users
		PropertyUtil.setProperty(PropertyUtil.REP_USERS_ALL, String.valueOf(rbtUsersAll.isSelected()));
		PropertyUtil.setProperty(PropertyUtil.REP_USERS, txtUsers.getText());

		// Period
		PropertyUtil.setProperty(PropertyUtil.REP_PERIOD_ALL, String.valueOf(rbtPeriodAll.isSelected()));
		if (!txtPeriodFrom.hasDateError() || !txtPeriodFrom.hasFormatError()) {
			PropertyUtil.setProperty(PropertyUtil.REP_PERIOD_FROM, SwingUtil.calendarDateFormat.format(dChooserFrom.getDate()));
		}
		if (!txtPeriodTo.hasDateError() || !txtPeriodTo.hasFormatError()) {
			PropertyUtil.setProperty(PropertyUtil.REP_PERIOD_TO, SwingUtil.calendarDateFormat.format(dChooserTo.getDate()));
		}
		PropertyUtil.setProperty(PropertyUtil.REP_INTERVAL_FROM, SwingUtil.timeFormat.format(sIntervalFrom.getValue()));
		PropertyUtil.setProperty(PropertyUtil.REP_INTERVAL_TO, SwingUtil.timeFormat.format(sIntervalTo.getValue()));

		// Saving options
		PropertyUtil.setProperty(PropertyUtil.REP_SHOW_CHARTS, String.valueOf(chbShowCharts.isSelected()));
		PropertyUtil.setProperty(PropertyUtil.REP_SAVE_CHARTS, String.valueOf(chbSaveCharts.isSelected()));
	}

	public void loadDefaultOptions() {
		PropertyUtil.setDefaultCombinedProperties();
		loadOptions();
	}

	public void generate() {
		TreeSet<Integer> userIDs = null;

		if (!rbtUsersAll.isSelected()) {
			if (!txtUsers.hasError()) {
				userIDs = getUsers(txtUsers);
			} else {
				//error
			}
		} else {
			// get all the subjects in the DB
			userIDs = getUsers();
		}

		CombinedReport combinedReport = new CombinedReport(
				userIDs,
				dChooserFrom.getDate(),
				dChooserTo.getDate(),
				(Date) sIntervalFrom.getValue(),
				(Date) sIntervalTo.getValue(),
				chbShowCharts.isSelected(),
				chbSaveCharts.isSelected(),
				listLayersModel,
				accPane,
				gpsPane,
				nfcPane,
				new int[]{
						jsAccelerometerNoData.getValue(),
						jsAccelerometerGeneral.getValue(),
						jsGPSNoData.getValue(),
						jsGPSHome.getValue(),
						jsGPSOut.getValue(),
						jsNFCNoData.getValue(),
						jsNFCGeneral.getValue()}
		);


		combinedReport.createCharts();

	}


	public void actionReloadPreview() {
		nfcPane.repaintBlockPreview();
		gpsPane.repaintBlockPreview();
		pCombinedPreview.repaint();
	}

	public void actionMoveUp() {
		int index = listLayers.getSelectedIndex();
		if (index > 0) {
			String movedElement = (String) listLayersModel.get(index);
			listLayersModel.remove(index);
			listLayersModel.add(index - 1, movedElement);
			listLayers.setSelectedIndex(index - 1);

			updateLayers();
		}
	}

	public void actionMoveDown() {
		int index = listLayers.getSelectedIndex();
		if (index != -1 && index != listLayersModel.getSize() - 1) {
			String movedElement = (String) listLayersModel.get(index);
			listLayersModel.remove(index);
			listLayersModel.add(index + 1, movedElement);
			listLayers.setSelectedIndex(index + 1);

			updateLayers();
		}
	}


	private void checkTypeSelection() {
		JCheckBox[] checkBoxes = new JCheckBox[]{chbAccelerometer, chbGPS, chbNFC};
		int selected = 0;
		JCheckBox unselectedCheckbox = null;
		for (JCheckBox checkBox : checkBoxes) {
			if (checkBox.isSelected()) {
				selected++;
			} else {
				unselectedCheckbox = checkBox;
			}
		}
		if (selected == 2) {
			for (JCheckBox checkBox : checkBoxes) {
				checkBox.setEnabled(false);
			}
			unselectedCheckbox.setEnabled(true);
		} else {
			for (JCheckBox checkBox : checkBoxes) {
				checkBox.setEnabled(true);
			}
		}
	}

	private void setLayers() {
//		pCombinedPreview.setHasAccelerometer(chbAccelerometer.isSelected());
//		pCombinedPreview.setHasGPS(chbGPS.isSelected());
//		pCombinedPreview.setHasNFC(chbNFC.isSelected());
//
		pCombinedPreview.setLayers(listLayersModel);

		setCard(pAdvancedAccelerometer, chbAccelerometer.isSelected());
		setCard(pAdvancedGPS, chbGPS.isSelected());
		setCard(pAdvancedNFC, chbNFC.isSelected());
	}

	private void setCard(JPanel pane, boolean showing) {
		CardLayout cardLayout = (CardLayout) pane.getLayout();
		if (showing) {
			cardLayout.show(pane, "content");
		} else {
			cardLayout.show(pane, "empty");
		}
	}

	private void setLayerList() {
		listLayersModel.clear();
		if (chbAccelerometer.isSelected()) {
			listLayersModel.addElement("Accelerometer");
		}
		if (chbGPS.isSelected()) {
			listLayersModel.addElement("GPS");
		}
		if (chbNFC.isSelected()) {
			listLayersModel.addElement("NFC");
		}

		listLayers.setSelectedIndex(0);

		updateLayers();
	}

	private void updateLayers() {
		pCombinedPreview.setLayers(listLayersModel);
		pCombinedPreview.repaint();
	}


	class OpacityChangeListener implements ChangeListener {
		@Override
		public void stateChanged(ChangeEvent e) {
			jsAccelerometerNoData.setToolTipText(jsAccelerometerNoData.getValue() + "");
			jsAccelerometerGeneral.setToolTipText(jsAccelerometerGeneral.getValue() + "");
			jsGPSNoData.setToolTipText(jsGPSNoData.getValue() + "");
			jsGPSHome.setToolTipText(jsGPSHome.getValue() + "");
			jsGPSOut.setToolTipText(jsGPSOut.getValue() + "");
			jsNFCNoData.setToolTipText(jsNFCNoData.getValue() + "");
			jsNFCGeneral.setToolTipText(jsNFCGeneral.getValue() + "");
			pCombinedPreview.setAccNoDataOpacity(jsAccelerometerNoData.getValue());
			pCombinedPreview.setAccGeneralOpacity(jsAccelerometerGeneral.getValue());
			pCombinedPreview.setGpsNoDataOpacity(jsGPSNoData.getValue());
			pCombinedPreview.setGpsHomeOpacity(jsGPSHome.getValue());
			pCombinedPreview.setGpsOutOpacity(jsGPSOut.getValue());
			pCombinedPreview.setNfcNoDataOpacity(jsNFCNoData.getValue());
			pCombinedPreview.setNfcGeneralOpacity(jsNFCGeneral.getValue());
			pCombinedPreview.repaint();
		}
	}

	class AdvancedChangeListener2 implements ChangeListener {
		@Override
		public void stateChanged(ChangeEvent e) {
			jsNFCNoData.setToolTipText(jsNFCNoData.getValue() + "");
			pCombinedPreview.setNfcNoDataOpacity(jsNFCNoData.getValue());
			pCombinedPreview.repaint();
		}
	}

	class TypeActionListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			checkTypeSelection();
			setLayers();
			setLayerList();
		}
	}
}
